home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / print.arc / PINSTALL.C < prev    next >
Text File  |  1987-06-13  |  6KB  |  206 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <io.h>
  5. #include <process.h>
  6.  
  7. main()
  8. {
  9. int mono,escape,item,code,code1,code2,code3,i,c,j;
  10. char *sub_dir,subdir[20],label[80],file[30],temp[20];
  11. FILE *f1,*f2;
  12.  
  13.  
  14. mono = hardware(0);  /* check for a color card */
  15.  
  16. copyrite("PINSTALL\0","April 1986\0",mono);
  17. cls();
  18. printf("PRINT Printer Installation Routine\n\n");
  19.  
  20. /* Check for an existing configuration file.  If it exists, show it to
  21.    them and find out if they want to replace it.
  22. */
  23.  
  24. strncpy(file,"printer.cnf\0",13); /* set up the config file name */
  25. sub_dir = getenv("PRINT");  /* find the environmnet variable for print */
  26. strncpy(subdir,sub_dir,20);
  27. i=strlen(subdir);
  28. if ((subdir[i-1] !=92)&& (i>0)) {
  29.   subdir[i] = 92;   /* put in a backslash */
  30.   ++i;
  31.   }
  32. for (j=0; j<12; j++)
  33.   subdir[i++] = file[j]; /* copy the rest of the name to it */
  34.  
  35.  
  36. if ((f1=fopen(subdir,"r")) != NULL) {
  37.   printf("Printer configuration file already exists:\n\n");
  38.   fgets(label,80,f1); /* get the printer label */
  39.   printf("\n\nConfiguration for: %s\n",label);
  40.  
  41.   item = 1;
  42.   while ((c=getc(f1)) != EOF) {
  43.    ungetc(c,f1);
  44.    fgets(temp,20,f1); /* get the first label */
  45.    i=0;
  46.    while (temp[i++] != '\n');
  47.    temp[i-1] = ' '; /* get rid of the carriage return */
  48.    for (c=i; c<20; c++)
  49.     temp[c] = ' ';
  50.    temp[20] = '\0'; /* pad out to 20 characters for display purposes */
  51.  
  52.    fscanf(f1,"%d %d %d %d",&escape,&code1,&code2,&code3);
  53.    printf("<%2d> %s %2d %2d %2d <",item,temp,code1,code2,code3);
  54.    if (escape == 0)
  55.     printf("No leading escape (ASCII 27)>\n");
  56.    else
  57.     printf("   Leading escape (ASCII 27)>\n");
  58.    ++item;
  59.    }
  60.    fclose(f1);
  61.  
  62. printf("\n\nDo you wish to overwrite (replace) this data (y/n)? ");
  63. while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
  64. printf("\n\n");
  65.  
  66.  if ((c=='n') || (c=='N')) {
  67.    printf("\n\nAborting PINSTALL procedure\n\n");
  68.    exit(0);
  69.    }
  70.   else {
  71.    c=unlink(subdir);
  72.    if (c != NULL) {
  73.     printf("\n");
  74.     cprint("Error: Unable to delete old configuration file",131);
  75.     printf("\n\n");
  76.     exit(1);
  77.     }
  78.   }
  79. } /* end of if fopen != NULL) */
  80. printf("Ready for new printer parameters\n\n");
  81. printf("You may enter up to 7 different printer configuration codes\n");
  82. printf("for your printer.  You will be asked for a name for each\n");
  83. printf("configuration codes, and then for up to three character codes\n");
  84. printf("(exclusive of the escape code) to transmit to the printer.\n\n");
  85. printf("You will be prompted for the printer codes to handle enhanced\n");
  86. printf("print mode, return to normal print mode from enhance, and for\n");
  87. printf("a printer initialization string.\n\n");
  88.  
  89.  
  90. code = 0;
  91. item = 1;
  92. printf("\nWhat printer is this for: ");
  93. i=0;
  94. while (((label[i++] = getche()) != 13) && (i<60)) {
  95.  if (label[i-1] == 8)
  96.   i -=2; /* backspace for them */
  97.  }
  98. label[i-1] = '\0';
  99.  
  100. while (code == 0) {
  101. if (item == 1) {
  102.  printf("\nEnter your printer codes for ");
  103.  cprint("printer initialization",131);
  104.  strncpy(temp,"Printer Initialize\0",20);
  105.  printf("\n");
  106.  }
  107.  
  108. if (item == 2) {
  109.  printf("\nEnter your printer codes for ");
  110.  cprint("enhanced mode",131);
  111.  strncpy(temp,"Enhanced mode\0",20);
  112.  printf("\n");
  113.  }
  114.  
  115. if (item == 3) {
  116.  printf("\nEnter your printer codes for ");
  117.  cprint("switch from enhanced to normal mode ",131);
  118.  strncpy(temp,"Return to normal\0",20);
  119.  printf("\n");
  120.  }
  121.  
  122. if (item >3) {
  123.  printf("\nEnter the label for configuration code %3d ",item);
  124.  printf("+--------------------+\n");
  125.  printf(  "                                            ");
  126.  i=1;
  127.  temp[0] = ' '; /* put in a leading space */
  128.  while (((temp[i++]=getche()) != 13) && (i<20)) {
  129.   if (temp[i-1] == 8)
  130.     i -=2; /* backspace */
  131.   }
  132.  temp[i-1] = '\0'; /* put the eos marker on it */
  133.  }
  134.  
  135.  printf("\nDoes this code sequence require a leading escape (ASCII 27)? ");
  136.  while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
  137.  
  138.  if ((c=='y') || (c=='Y'))
  139.    escape = 1;
  140.   else
  141.    escape = 0;
  142.  
  143.  printf("\nYou may now enter up to three ascii codes to be transmitted\n");
  144.  printf("to your printer for this function.  Enter 0 for any codes you\n");
  145.  printf("do not wish to use.\n\n");
  146.  
  147.  printf("Enter ascii code 1: ");
  148.  scanf("%d",&code1);
  149.  printf("Enter ascii code 2: ");
  150.  scanf("%d",&code2);
  151.  printf("Enter ascii code 3: ");
  152.  scanf("%d",&code3);
  153.  
  154.  printf("You have entered:\n\n");
  155.  printf("Label:           ");
  156.  if (escape == 1)
  157.   printf("   %s\nPrinter Code: 27 ",temp);
  158.  else
  159.   printf("%s\nPrinter Code:    ",temp);
  160.  printf("%d %d %d\n\nIs this correct (y/n)? ",code1,code2,code3);
  161.  
  162.  while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
  163.  printf("\n\n");
  164.  
  165.  if ((c=='y') || (c=='Y')) { /* write the code to the file */
  166.   if ((f1=fopen(subdir,"a")) != NULL) {
  167.    if (item == 1)
  168.     fprintf(f1,"%s\n",label);
  169.  
  170.    fprintf(f1,"%s\n",temp);
  171.    fprintf(f1,"%d %d %d %d",escape,code1,code2,code3);
  172.    fclose(f1);
  173.    }
  174.   else {
  175.     printf("\n");
  176.     cprint("Error on open. Aborting,131");
  177.     printf("\n\n");
  178.     exit(1);
  179.     }
  180.    }
  181.   else
  182.    --item;
  183.  
  184. if (((item <=10)&& (item >2)) && ((c=='y') || (c=='Y'))) {
  185.  
  186.  printf("Do you wish to enter more (y/n)? ");
  187.  while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
  188.  
  189.  if ((c=='n') || (c=='N'))
  190.    code = 1; /* set up for the exit */
  191.    }
  192.    ++item;
  193.  
  194. } /* end of while code == 0 */
  195.  
  196. printf("\n\nPrinter initialization completed\n\n");
  197. printf("\n\nReminder: Don't forget to set the environment variable\n");
  198. printf("          if you have created this configuration in a directory\n");
  199. printf("          other than the root directory.\n\nExample:\n");
  200. printf("     If you created it in the \UTIL directory, you would add a\n");
  201. printf("     line to your AUTOEXEC.BAT file as follows:\n\n");
  202. printf("              SET PRINT=C:\UTIL\n\n");
  203.  
  204. } /* end of main */
  205.  
  206.